package com.zx.platform.dao.impl;

import com.zx.platform.dao.SysParamDao;
import com.zx.platform.dao.mapper.SysParamMapper;
import com.zx.platform.dao.model.SysParam;
import com.zx.platform.dao.model.SysParamExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 14-3-1
 * Time: 上午10:54
 * To change this template use File | Settings | File Templates.
 */
@Component("SysParamDao")
public class SysParamImpl implements SysParamDao {

    @Autowired
    private SysParamMapper mapper;

    /**
     * 新增
     */
    public Integer add(SysParam sysParam) throws DataAccessException {
        int column = mapper.insert(sysParam);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return sysParam.getParamId();
    }

    /**
     * 修改
     * @param sysParam
     * @return
     * @throws DataAccessException
     */
    public Integer update(SysParam sysParam) throws DataAccessException {
        int column = mapper.updateByPrimaryKeySelective(sysParam);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return sysParam.getParamId();
    }

    /**
     * 删除
     */
    public void delete(SysParam sysParam) throws DataAccessException {
        int column = mapper.deleteByPrimaryKey(sysParam.getParamId());
        if (column != 1) {
            throw new RuntimeException("");
        }
    }

    /**
     * 分页查找
     */
	public List<SysParam> getPageByExample(int pageSize, int pageBegin,
			SysParamExample example) throws DataAccessException {
		return mapper.getPageByModel(pageSize, pageBegin, example); 
	}
	/**
	 * 查找条数
	 * 
	 * @param example
	 * @return
	 * @throws DataAccessException
	 */
	public int countByExample(SysParamExample example) throws DataAccessException {
		return mapper.countByExample(example);
	}

	/**
	 * 
	 */
	public List<SysParam> getListByExample(SysParamExample example)
			throws DataAccessException {
		if(example==null){
			example= new SysParamExample();
		}
		example.setOrderByClause("orders");
		return mapper.selectByExample(example); 
	}

	public SysParam selectByPrimaryKey(Integer key) throws DataAccessException {
		return mapper.selectByPrimaryKey(key);
	}
}
